import 'package:library_base/entities/login_bean_entity.dart';
import 'package:library_base/net/apis.dart';
import 'package:library_base/provider/base_controller.dart';
import 'package:library_base/route/routers.dart';
import 'package:library_base/utils/sp_util.dart';
import 'package:get/get.dart';

class MainController extends BaseController {
  @override
  Future requestData() {
    requestUniversal<LoginBeanEntity>(Apis.REFRESH_TOKEN,
        isSendShowDialog: false,
        queryParameters: {"refreshToken": SPUtil.refreshToken}, resultSuccessCall: (data) {
      SPUtil.token = data.accessToken;
      SPUtil.expiresTime = data.expiresTime;
      SPUtil.refreshToken = data.refreshToken;
      SPUtil.userId = data.userId;
    }, resultFailCall: (msg, code) {
      if (code == 400 || code == 401) {
        SPUtil.token = "";
        Get.offAndToNamed(Routers.login);
      }
    });
    return super.requestData();
  }
}
